import Vue from 'vue'
import VueRouter from 'vue-router'
const App=r=>require.ensure([],()=>r(require('@/App.vue')),'App')
const home=r=>require.ensure([],()=>r(require('@/views/Home/Home.vue')),'home')
const login=r=>require.ensure([],()=>r(require('@/views/Login/Login.vue')),'login')
const addArticle=r=>require.ensure([],()=>r(require('@/views/Article/children/addArticle.vue')),'addArticle')
const selectArticle=r=>require.ensure([],()=>r(require('@/views/Article/selectAritcle.vue')),'selectArticle')
const EditArticle=r=>require.ensure([],()=>r(require('@/views/Article/children/EditArticle.vue')),'EditArticle')
const recycle=r=>require.ensure([],()=>r(require('@/views/Article/children/recycle.vue')),'recycle')
const Index=r=>require.ensure([],()=>r(require('@/views/Reception/Index/index.vue')),'Index')
const content=r=>require.ensure([],()=>r(require('@/views/Reception/Content/content.vue')),'content')
const indexLogin = r=>require.ensure([],()=>r(require('@/views/Login/indexLogin.vue')),'indexLogin')
const indexArticle=r=>require.ensure([],()=>r(require('@/views/Reception/Article/articleIndex.vue')),'indexArticle')
const register=r=>require.ensure([],()=>r(require('@/views/Register/register.vue')),'register')
const comment=r=>require.ensure([],()=>r(require('@/views/Comment/comment.vue')),'comment')
const selectClass=r=>require.ensure([],()=>r(require('@/views/Fclass/selectClass.vue')),'selectClass')
const updateClass=r=>require.ensure([],()=>r(require('@/views/Fclass/children/updateClass.vue')),'updateClass');
const deleteAllCom=r=>require.ensure([],()=>r(require('@/views/Comment/children/deleteAllCom.vue')),'deleteAllCom');
const Lable=r=>require.ensure([],()=>r(require('@/views/Lable/lable.vue')),'Lable');
const updateTable=r=>require.ensure([],()=>r(require('@/views/Lable/children/updateLable.vue')),'updateTable');
const FriendChain=r=>require.ensure([],()=>r(require('@/views/FriendChain/FriendChain.vue')),'FriendChain');
const FriendUpdate=r=>require.ensure([],()=>r(require('@/views/FriendChain/children/updateFriend.vue')),'FriendUpdate');
const userInfo=r=>require.ensure([],()=>r(require('@/views/User/userInfo.vue')),'userInfo');
const redirect=r=>require.ensure([],()=>r(require('@/views/Error/404.vue')),'redirect');
Vue.use(VueRouter)


const routes = [
  {
    path: '/',
    name: 'App',
    component:App,
    children: [{
      path:'',
      redirect:'/index'
    },{
      path:'home',
      name:'Home',
      component:home,
      children: [{
        path:'addArticle',
        name:'AddArticle',
        component:addArticle
      },{
        path:'selectArticle',
        name:'SelectArticle',
        component:selectArticle
      },{
        path:'editArticle',
        name:'EditArticle',
        component:EditArticle
      },{
        path:'recycle',
        name:'Recycle',
        component:recycle
      },{
        path:'comment',
        name:'Comment',
        component:comment
      },{
        path:'selectClass',
        name:'SelectClass',
        component:selectClass
      },{
        path:'updateClass',
        name:'UpdateClass',
        component:updateClass
      },{
        path:'deleteAllCom',
        name:'DeleteAllCom',
        component:deleteAllCom
      },{
        path:'lable',
        name:'Lable',
        component:Lable,
      },{
        path:'updateTable',
        name:'UpdateTable',
        component:updateTable
      },{
        path:'FriendChain',
        name:'FriendChain',
        component:FriendChain
      },
      {
        path:'FriendUpdate',
        name:'FriendUpdate',
        component:FriendUpdate
      },{
        path:'userInfo',
        name:'UserInfo',
        component:userInfo
      }
      ]
    },{
      path:'login',
      name:'Login',
      component:login
    },{
      path:'index',
      name:'Index',
      component:Index,
      redirect:'/index/content',
      children:[{
        path:'content',
        name:'content',
        component:content
      },{
        path:'indexLogin',
        name:'IndexLogin',
        component:indexLogin
      },{
        path:'indexArticle',
        name:'IndexArticle',
        component:indexArticle
      },{
        path:'register',
        name:'Register',
        component:register
      }
    ]
    },{
      path:'redirect',
      name:'Redirect',
      component:redirect
    }]
  },{
    path:'*',
    redirect:'/redirect'
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
let nexts;
router.beforeEach((to,from,next)=>{
  let admin=to.path.split('/');

  var isLogin=sessionStorage.getItem('token');

  if(admin[1]=='home'){
    if(isLogin){
      next();
     
    }else{
      next({name:'Login'});
    }

  }
  else{
      next();
  }
})

export default router
